# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

pkgbase=libgcrypt
pkgname=('libgcrypt' 'libgcrypt-devel')
pkgver=1.9.2
pkgrel=1
pkgdesc="General purpose cryptographic library based on the code from GnuPG"
arch=(i686 x86_64)
url="https://gnupg.org"
license=('LGPL')
depends=('libgpg-error')
makedepends=('libgpg-error-devel')
options=('!emptydirs')
source=(https://gnupg.org/ftp/gcrypt/${pkgname}/${pkgname}-${pkgver}.tar.bz2
        libgcrypt-1.7.3-ecc-test-fix.patch
        libgcrypt-1.8.0-use-poll.patch
        libgcrypt-1.6.1-msys2.patch)
sha256sums=('b2c10d091513b271e47177274607b1ffba3d95b188bbfa8797f948aec9053c5a'
            '3a420cc2b238203b1d107bb20313bfdaa79f8a1358678a2f222093223132038c'
            'ffa8d8dcb6193ff85f8f978625f24e589985dbe22e1858af9b52cd141a76052f'
            'cd7f58dc81a13328e34e0de8c6011196b5a2aa61b69dd611d4d7579ebf6cbb32')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  patch -p1 -i ${srcdir}/libgcrypt-1.7.3-ecc-test-fix.patch
  patch -p1 -i ${srcdir}/libgcrypt-1.8.0-use-poll.patch
  patch -p1 -i ${srcdir}/libgcrypt-1.6.1-msys2.patch

  autoreconf -fi
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}
  ./configure \
    --prefix=/usr \
    --build=${CHOST} \
    --enable-shared \
    --enable-static \
    --exec-prefix=/usr \
    --localstatedir=/var \
    --sysconfdir=/etc \
    --docdir=/usr/share/doc/libgcrypt \
    --htmldir=/usr/share/doc/libgcrypt/html \
    --config-cache \
    --disable-asm

  make no_undefined=-no-undefined
  make DESTDIR=${srcdir}/dest install
}

check() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make check
}

package_libgcrypt() {
  groups=('libraries')
  install=${pkgname}.install

  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  rm -f ${pkgdir}/usr/bin/*-config
  cp -rf ${srcdir}/dest/usr/share/info ${pkgdir}/usr/share/
}

package_libgcrypt-devel() {
  pkgdesc="Libgcrypt headers and libraries"
  groups=('development')
  options=('staticlibs')
  depends=("libgcrypt=${pkgver}" 'libgpg-error-devel')

  mkdir -p ${pkgdir}/usr/{bin,share}
  cp -f ${srcdir}/dest/usr/bin/*-config ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share/aclocal ${pkgdir}/usr/share/
}
